﻿using System;
using System.Web;

using DotNetNuke.Services.Tokens;

namespace DotNetNuke.Modules.UserDefinedTable
{

    public class TokenReplace : DotNetNuke.Services.Tokens.TokenReplace
    {
        private bool escapeApostrophe;

        public TokenReplace() : this(false)
        {
        }

        public TokenReplace(bool EscapeApostrophe)
        {
            this.escapeApostrophe = false;
            this.escapeApostrophe = EscapeApostrophe;
            if (HttpContext.Current != null)
            {
                HttpRequest request = System.Web.HttpContext.Current.Request;
                base.PropertySource["querystring"] = new FilteredNameValueCollectionPropertyAccess(request.QueryString);
                base.PropertySource["form"] = new FilteredNameValueCollectionPropertyAccess(request.Form);
                base.PropertySource["server"] = new FilteredNameValueCollectionPropertyAccess(request.ServerVariables);
            }
        }

        protected override string replacedTokenValue(string strObjectName, string strPropertyName, string strFormat)
        {
            string str2 = base.replacedTokenValue(strObjectName, strPropertyName, strFormat);
            if (this.escapeApostrophe)
            {
                str2 = str2.Replace("'", "''");
            }
            return str2;
        }
    }
}

